<!DOCTYPE html>
<html lang="zh-CN" data-theme="light">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}{% endblock %}</title>
    <!-- Bootstrap CSS -->
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.1.3/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet">
    <!-- Highlight.js CSS -->
    <link href="https://cdn.bootcdn.net/ajax/libs/highlight.js/11.7.0/styles/atom-one-light.min.css" rel="stylesheet">
    <!-- 自定义水墨风格 CSS -->
    <link href="{{ url_for('static', filename='css/ink_style.css') }}?v=1.1" rel="stylesheet">
    <!-- 深色/浅色模式自适应文字颜色 -->
    <link href="{{ url_for('static', filename='css/theme_colors.css') }}?v=1.0" rel="stylesheet">
    {% block styles %}{% endblock %}
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg navbar-dark">
        <div class="container">
            <a class="navbar-brand" href="{{ url_for('index') }}">
                <i class="fas fa-book-reader"></i> 墨韵
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('index') }}">
                            <i class="fas fa-home"></i> 首页
                        </a>
                    </li>
                    {% if current_user.is_authenticated %}
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('forum') }}">
                            <i class="fas fa-comments"></i> 论坛
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('circles') }}">
                            <i class="fas fa-users"></i> 圈子
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('books') }}">
                            <i class="fas fa-book"></i> 电子书
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('upload_book') }}">
                            <i class="fas fa-upload"></i> 上传电子书
                        </a>
                    </li>
                    {% if current_user.is_admin %}
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('admin_panel') }}">
                            <i class="fas fa-cog"></i> 管理面板
                        </a>
                    </li>
                    {% endif %}
                    {% endif %}
                </ul>
                <ul class="navbar-nav">
                    <!-- 暗黑模式切换 -->
                    <li class="nav-item d-flex align-items-center mx-2">
                        <i class="fas fa-sun theme-icon" id="light-icon"></i>
                        <label class="theme-switch">
                            <input type="checkbox" id="theme-toggle">
                            <span class="theme-slider"></span>
                        </label>
                        <i class="fas fa-moon theme-icon" id="dark-icon"></i>
                    </li>
                    
                    {% if current_user.is_authenticated %}
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('profile') }}">
                            <i class="fas fa-user-circle"></i> 
                            {{ current_user.username }}
                            {% if current_user.is_admin %}
                            <span class="admin-badge">管理员</span>
                            {% endif %}
                            {% if current_user.notifications.filter_by(is_read=False).count() > 0 %}
                            <span class="badge rounded-pill bg-danger">
                                {{ current_user.notifications.filter_by(is_read=False).count() }}
                            </span>
                            {% endif %}
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('logout') }}">
                            <i class="fas fa-sign-out-alt"></i> 退出
                        </a>
                    </li>
                    {% else %}
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('login') }}">
                            <i class="fas fa-sign-in-alt"></i> 登录
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('register') }}">
                            <i class="fas fa-user-plus"></i> 注册
                        </a>
                    </li>
                    {% endif %}
                </ul>
            </div>
        </div>
    </nav>

    <!-- 主要内容 -->
    <div class="container py-4">
        {% with messages = get_flashed_messages(with_categories=true) %}
        {% if messages %}
        {% for category, message in messages %}
        <div class="alert alert-{{ category if category != 'message' else 'info' }} alert-dismissible fade show" role="alert">
            {{ message }}
            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
        </div>
        {% endfor %}
        {% endif %}
        {% endwith %}

        {% block content %}{% endblock %}
    </div>

    <!-- 页脚 -->
    <footer class="footer mt-auto py-3 bg-dark text-light">
        <div class="container text-center">
            <span>© 2024 墨韵图书共享平台 | 知识的海洋，智慧的殿堂</span>
        </div>
    </footer>

    <!-- jQuery -->
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <!-- Bootstrap Bundle JS -->
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.1.3/js/bootstrap.bundle.min.js"></script>
    <!-- Highlight.js -->
    <script src="https://cdn.bootcdn.net/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
    
    <!-- 主题切换脚本 -->
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const themeToggle = document.getElementById('theme-toggle');
            const htmlElement = document.documentElement;
            
            // 检查本地存储中的主题设置
            const savedTheme = localStorage.getItem('theme');
            if (savedTheme === 'dark') {
                htmlElement.setAttribute('data-theme', 'dark');
                themeToggle.checked = true;
                
                // 切换代码高亮样式为深色模式
                switchCodeTheme('dark');
            }
            
            // 监听切换事件
            themeToggle.addEventListener('change', function() {
                if (this.checked) {
                    htmlElement.setAttribute('data-theme', 'dark');
                    localStorage.setItem('theme', 'dark');
                    
                    // 切换代码高亮样式为深色模式
                    switchCodeTheme('dark');
                } else {
                    htmlElement.setAttribute('data-theme', 'light');
                    localStorage.setItem('theme', 'light');
                    
                    // 切换代码高亮样式为浅色模式
                    switchCodeTheme('light');
                }
            });
            
            // 切换代码高亮主题
            function switchCodeTheme(theme) {
                const currentThemeLink = document.querySelector('link[href*="highlight.js"]');
                if (currentThemeLink) {
                    if (theme === 'dark') {
                        currentThemeLink.href = 'https://cdn.bootcdn.net/ajax/libs/highlight.js/11.7.0/styles/atom-one-dark.min.css';
                    } else {
                        currentThemeLink.href = 'https://cdn.bootcdn.net/ajax/libs/highlight.js/11.7.0/styles/atom-one-light.min.css';
                    }
                }
            }
        });
    </script>
    
    <!-- 水墨动画效果 -->
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const buttons = document.querySelectorAll('.btn');
            
            buttons.forEach(button => {
                button.addEventListener('click', function(e) {
                    // 创建水墨效果
                    const inkEffect = document.createElement('div');
                    inkEffect.classList.add('ink-splash');
                    this.appendChild(inkEffect);
                    
                    // 定时移除效果
                    setTimeout(() => {
                        inkEffect.remove();
                    }, 1000);
                });
            });
        });
    </script>
    
    <!-- 初始化代码高亮 -->
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 初始化代码高亮
            hljs.highlightAll();
        });
    </script>
    
    {% block scripts %}{% endblock %}
</body>
</html> 